package com.example.mypro;

import java.util.List;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import com.example.adapter.Tsper_LvAdpater;
import com.example.domain.TuShu;
import com.example.factory.ServiceFactory;
import com.example.service.XueShengService;

public class TspersonActivity extends Activity implements OnClickListener {
private ListView listView;
private XueShengService xueShengService;
private Button search;
private List<TuShu> list = null;
private GetData getData;
private  EditText xhEditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
xueShengService=ServiceFactory.getShengService();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tsperson);
listView = (ListView) findViewById(R.id.tsperson_lv);
search =(Button) findViewById(R.id.tsperson_search);
xhEditText =(EditText)findViewById(R.id.xh);
search.setOnClickListener(this);
listView.setVisibility(View.INVISIBLE);

}

@SuppressLint("ShowToast")
class GetData extends AsyncTask<Void, Void, List<TuShu>> {

@SuppressLint("ShowToast")
@Override
protected List<TuShu> doInBackground(Void... params) {
	System.out.println("doInBackground");
	String xh=xhEditText.getText().toString();
	list = xueShengService.getXueShengJieYueXinXis(xh);
	return list;
}

@Override
protected void onProgressUpdate(Void... values) {
	super.onProgressUpdate(values);

}

@Override
protected void onPostExecute(List<TuShu> result) {
	super.onPostExecute(result);
	System.out.println("onProgressUpdate");
	if (list != null) {
		System.out.println("这里没错");
		listView.setVisibility(View.VISIBLE);
		Tsper_LvAdpater adapter = new Tsper_LvAdpater(list,
				TspersonActivity.this);
		listView.setAdapter(adapter);
	}
}

}

@Override
public void onClick(View v) {
if (v.getId() == R.id.tsperson_search) 
{
	getData = new GetData();
	getData.execute();	
}
}


}
